package com.bw.usercenter.contract

import com.bw.mvpcore.BasePresenter
import com.bw.mvpcore.BaseRepository
import com.bw.mvpcore.IModel
import com.bw.mvpcore.IView
import com.bw.net.protocol.resp.BaseRespEntity
import com.bw.usercenter.callback.LoginCallback
import com.bw.usercenter.model.protocol.req.UserEntitiy
import com.bw.usercenter.model.protocol.resp.*
import io.reactivex.Observable
import io.reactivex.Observer

/**
 * 契约类
 */
interface UserCenterContract {
    /**
     * Model层
     */
    interface  UserContractModel : IModel{
        fun register(enity:UserEntitiy):Observable<BaseRespEntity<RespUserEntity>>
        fun login(enity: UserEntitiy):Observable<BaseRespEntity<RespUserEntity>>
        fun requestTB(page:Int):Observable<RespGoodEntity>
        fun getRecomment():Observable<RespRecommendEntity>
        fun getauthcode():Observable<Int>
        fun getSrarch(name:String):Observable<RespSearchEntity>
        fun getSearchitem(string: String):Observable<RespSearchitemIDEntity>
    }
    /**
     * 仓库
     */
    abstract  class UserCenterRepository:BaseRepository<UserContractModel>(){
        abstract fun register(enity:UserEntitiy):Observable<BaseRespEntity<RespUserEntity>>
        abstract fun login(enity:UserEntitiy):Observable<BaseRespEntity<RespUserEntity>>
        abstract fun requestTB(page:Int):Observable<RespGoodEntity>
        abstract fun getRecomment():Observable<RespRecommendEntity>
        abstract fun getauthcode():Observable<Int>
        abstract fun getSrarch(name:String):Observable<RespSearchEntity>
        abstract fun getSearchitem(string: String):Observable<RespSearchitemIDEntity>
    }
    /**
     * View层
     */
    interface UserCenterView:IView{
        fun <T> registerSuccess(data:T)
        fun registerSuccess(data:RespRecommendEntity)
        fun registerFaild(throwable: Throwable)
        fun registerSrech(respSearchEntity: RespSearchEntity)
        fun getSearchitem(respSearchitemIDEntity: RespSearchitemIDEntity)
    }
    /**
     * P层
     */
    abstract class UserCenterPresenter(view:UserCenterView):BasePresenter<UserCenterRepository,UserCenterView>(view){
        //注册
        abstract fun register(enity:UserEntitiy)
        //登录
        abstract fun login(enity:UserEntitiy)
        //获取推荐商品
        abstract fun requestTB(page:Int)
        //获取验证码
        abstract fun getauthcode()
        //推荐
        abstract fun getRecomment()
        //搜索
        abstract fun getSerch(name: String)
        //id搜索
        abstract fun getSearchitem(itemid: String)
    }
}